const Resource = require('../models/Resource');
const mongoose = require('mongoose');

const seedResources = [
  {
    title: '社区回收站',
    type: '回收点',
    description: '专业回收各类可回收物，支持上门回收服务',
    address: '北京市海淀区西二旗大街1号',
    location: [116.307629, 40.056878],
    openHours: '周一至周日 9:00-18:00',
    contact: '010-12345678',
    tags: ['可回收物', '上门服务'],
    status: 'active',
    startDate: new Date(),
    endDate: new Date(Date.now() + 30 * 24 * 60 * 60 * 1000),
    maxParticipants: 0,
    checkInRequired: 0,
    participants: []
  },
  {
    title: '环保志愿活动',
    type: '活动',
    description: '社区环保知识宣传和垃圾分类指导',
    address: '北京市海淀区中关村大街1号',
    location: [116.310316, 39.986456],
    time: '2024-03-30 14:00-16:00',
    contact: '13812345678',
    tags: ['志愿服务', '环保宣传'],
    status: 'active',
    startDate: new Date(),
    endDate: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000),
    maxParticipants: 50,
    checkInRequired: 1,
    participants: []
  },
  {
    title: '垃圾分类讲座',
    type: '活动',
    description: '专业讲师讲解垃圾分类知识，现场互动答疑',
    address: '北京市朝阳区建国路1号',
    location: [116.458, 39.914],
    time: '2024-03-25 15:00-17:00',
    contact: '13987654321',
    tags: ['环保教育', '垃圾分类'],
    status: 'active',
    startDate: new Date(),
    endDate: new Date(Date.now() + 14 * 24 * 60 * 60 * 1000),
    maxParticipants: 100,
    checkInRequired: 2,
    participants: []
  },
  {
    title: '废品回收中心',
    type: '回收点',
    description: '专业回收废纸、塑料、金属等可回收物',
    address: '北京市朝阳区东三环中路1号',
    location: [116.447, 39.921],
    openHours: '周一至周六 8:00-17:00',
    contact: '010-87654321',
    tags: ['废品回收', '上门服务'],
    status: 'active',
    startDate: new Date(),
    endDate: new Date(Date.now() + 365 * 24 * 60 * 60 * 1000),
    maxParticipants: 0,
    checkInRequired: 0,
    participants: []
  }
];

async function seedDatabase() {
  try {
    await mongoose.connect('mongodb://localhost:27017/green_planet');
    await Resource.deleteMany({});
    const result = await Resource.insertMany(seedResources);
    console.log(`成功添加 ${result.length} 条数据`);
    const count = await Resource.countDocuments();
    console.log(`数据库中现有 ${count} 条资源记录`);
    console.log('数据添加成功');
    process.exit(0);
  } catch (error) {
    console.error('数据添加失败:', error);
    process.exit(1);
  }
}

seedDatabase(); 